﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogicUniversityBiz;
namespace LogicUniversity.clerks
{
    public partial class Disbursement : System.Web.UI.Page
    {
        string dept_Code;

        public string Dept_Code
        {
            get { return dept_Code; }
            set { dept_Code = value; }
        }
        int batch_No;

        public int Batch_No
        {
            get { return batch_No; }
            set { batch_No = value; }
        }
        RetrievalListController retController;
        List<DisbursementData> result;
        protected void Page_PreInit(Object sender, EventArgs e)
        {
            //(Session["Role"]
            if (Session["Role"] as string != "Clerk")
            {
                Response.Redirect("~/Login.aspx");
            }

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                result = new List<DisbursementData>();
                retController = new RetrievalListController();
                result = retController.getDisbursementList();

                if (result == null || result.Count <= 0)
                {
                    lblMsg.Text = "Currently No Disbursement List.";
                    btnFinsih.Visible = false;
                }
                else
                {
                    grdDisbursementList.DataSource = result;
                    grdDisbursementList.DataBind();
                    this.ViewState["result"] = result;
                }
            }
        }

        protected void grdDisbursementList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Disburse")
            {
                result = (List<DisbursementData>)(this.ViewState["result"]);
                int row = Convert.ToInt16(e.CommandArgument);
                Dept_Code = result[row].Dept_No;
                Batch_No = result[row].Batch_No;
                Server.Transfer("Disbursement_Detail.aspx");
            }
        }

        protected void btnFinsih_Click(object sender, EventArgs e)
        {
            int i = 0;
            retController = new RetrievalListController();
            result = new List<DisbursementData>();
            result = retController.getDisbursementList();
            foreach (GridViewRow row in grdDisbursementList.Rows)
            {
                CheckBox chk = row.Cells[0].Controls[0] as CheckBox;
                if (chk.Checked != true)
                {
                    retController.unDisburseRetrieval(result[i]);
                }
                i++;
            }
        }
    }
}